package cn.jhc.survey;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import jakarta.servlet.http.HttpServletRequest;

@RestController
public class HelloController {
    
    @GetMapping("/hello")
    public String hello(){
        return "Hello web world!";
    }

    @PostMapping("/survey.do")
    public String handleSubmit(HttpServletRequest request){
        String name = request.getParameter("name");
        String age = request.getParameter("age");
        String gender = request.getParameter("gender");
        String phone = request.getParameter("phone"); 
        
        
        String province = request.getParameter("province");
        String city = request.getParameter("city");
        String district = request.getParameter("district");
        String detailAddress = request.getParameter("detailAddress");
        
        
        String address = province + city + district + detailAddress;
        
        
        String occupation = request.getParameter("occupation") != null ? 
                           request.getParameter("occupation") : "";
        String income = request.getParameter("income") != null ? 
                       request.getParameter("income") : "";
        
        
        String[] hobbies = request.getParameterValues("hobbies");
        String hobbiesStr = hobbies != null ? String.join(",", hobbies) : "";
        
        // 返回完整的提交结果
        return String.format("提交成功！\n姓名: %s\n年龄: %s\n性别: %s\n电话: %s\n地址: %s\n职业: %s\n收入: %s\n爱好: %s",
                           name, age, gender, phone, address, occupation, income, hobbiesStr);
    }
    
}
    
    